<?php

namespace app\admin\job;

use app\admin\service\SiteSiteService;
use app\common\job\BaseScheduledTask;


/**
 * 检查站点有效期
 */
class CheckSiteExpirationJob extends BaseScheduledTask
{


    protected string $name = 'checkSiteExpirationJob';


    protected string $title = '检查站点有效期';


    /**
     * 默认的cron表达式
     * @var string
     */
    protected string $cronExpression = '* * * * *';


    /**
     * @return string
     */
    public function getClassName(): string
    {
        return __CLASS__;
    }


    public function doJob(array $data = []): bool
    {
        $siteList = (new SiteSiteService())->list();
        $now = time();
        $this->log('当前时间：' . date('Y-m-d H:i:s', $now));
        $this->log('站点总数：' . $siteList->count());
        $siteList->each(function ($item) use ($now) {
            if ($item['expiration_time'] < $now) {
                $item->status = 0;
                $item->save();
            }
        });
        return true;
    }


    public function failed($data): void
    {
        // TODO: Implement failed() method.
    }


}